package com.chenyaowei.happyhub.controller;

import com.chenyaowei.happyhub.mapper.IndexNavMapper;
import com.chenyaowei.happyhub.pojo.IndexNav;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/admin")
public class AdminTypeController {
    @Resource
    IndexNavMapper indexNavMapper;
    @RequestMapping("/addtype")
    String addType(){
        return "addType";
    }
    @RequestMapping("/showtype")
    String showType(Model model){
        List<IndexNav> indexNavList=indexNavMapper.selectAllType();
        model.addAttribute("indexNavList",indexNavList);
        return "type";
    }
    @RequestMapping("/inserttype")
    String insertType(Model model,String typeName,String typeImage,String isIndex){
        indexNavMapper.insertType(typeName,typeImage,isIndex);
        List<IndexNav> indexNavList=indexNavMapper.selectAllType();
        model.addAttribute("indexNavList",indexNavList);
        return "type";
    }
    @RequestMapping("/deletetype")
    String deleteType(Model model,String type){
        indexNavMapper.deleteType(type);
        List<IndexNav> indexNavList=indexNavMapper.selectAllType();
        model.addAttribute("indexNavList",indexNavList);
        return "type";
    }
}
